package uml.behavioral.observer.ext;

/**
 * on 2023/1/4 17:05
 */
public class CarDriver implements Driver {
    private String carId;
    private boolean passed;
    private Light light;

    public CarDriver(String carId, boolean passed) {
        this.carId = carId;
        this.passed = false;
    }

    @Override
    public boolean isPassed() {
        return passed;
    }

    public void setPassed(boolean passed) {
        this.passed = passed;
    }

    @Override
    public void actAccordingTo(Light light) {
        this.light = light;
        if (this.light.getState().equals("绿灯") && this.light.getLightTime() >= 3) {
            System.out.println(carId + "已通过红绿灯路口");
            this.passed = true;
            light.hasBeenObservedBy(this);
            this.light = null;
        } else {
            light.willBeObservedBy(this);
            this.passed = false;
            System.out.println(carId + " 正在观察 " + light);
        }
    }
}
